***REPRODUCTION CODE
*SOFTWARE: STATA 14
*PANTALEAO 2025, APSR*
*PEACE DIVIDENDS

**PACKAGES

*ssc install reghdfe, replace
*ssc install csdid
*net install csdid2, from("https://friosavila.github.io/stpackages")

cd "\Replication package"


**FIGURE 1 - HOMICIDE REDUCTION

clear
use homicides_sp
set scheme sj
label variable ho_dol "Homicides"
label variable ano " "
line ho_dol ano
graph export "Production\Figure1_homicides.pdf", replace



***FIGURE 2 - PCC EXPANSION

clear
use pcc_expansion_aps
label variable share " "
label variable ano_rais " "
line share ano_rais, title("Expansion of PCC in the sample")
graph export "Production\Figure2_pccexpansion.pdf", replace



***FIGURE 3 --- MAP OF APs
***DONE IN QGIS SHARED AS PDF



*Table 1: Descriptive Statistics based on data from (GeoSampa, 2016)
clear
use data_jobs_firms

sum empregos_total empresas log_empregos_total log_empresas


*Table 2: Simple DiD estimate using (Callaway et al., 2021)  

clear
use data_jobs_firms
 
csdid2 log_empregos_total subpref2, ivar(cod_aed_s) time(ano_rais) gvar(tratamento) notyet
estat simple

csdid2 log_empresas subpref2, ivar(cod_aed_s) time(ano_rais) gvar(tratamento) notyet
estat simple


*Copy-paste into excel, format table and insert in word outreg2 does not work properly



****Table 3: drDiD estimate using (Callaway et al., 2021)
clear
use data_jobs_firms

csdid2 log_empregos_total subpref2, ivar(cod_aed_s) time(ano_rais) gvar(tratamento) notyet
estat event 

csdid2 log_empresas subpref2, ivar(cod_aed_s) time(ano_rais) gvar(tratamento) notyet
estat event

*Copy-paste into excel, format table and insert in word outreg2 does not work properly


***Figure 4: Job creation subsequent to PCC entry. The event-study displays the evolution of outcomes over time.
clear
use data_jobs_firms
set scheme sj


csdid2 log_empregos_total subpref2, ivar(cod_aed_s) time(ano_rais) gvar(tratamento) notyet
estat event 
csdid2_plot,  title("`z'")
graph play "csdid_red_blue"
graph export "Production\Figure4_csdid_log_jobs.pdf", replace




***Figure 5: Firm openings subsequent to PCC entry. The event-study displays the evolution of outcomes over time.

clear
use data_jobs_firms
set scheme sj

csdid2 log_empresas subpref2, ivar(cod_aed_s) time(ano_rais) gvar(tratamento) notyet
estat event
csdid2_plot,  title("`z'")
graph play "csdid_red_blue"
graph export "Production\Figure5_csdid_log_firms.pdf", replace



***Figure 6: Nighttime luminosity subsequent to PCC entry. The event-study displays the evolution of outcomes over time.

clear
use  "night_lights.dta"
set scheme sj


csdid2 stddmsp2  feature_x feature_y  mindmsp, ivar(id_2) t(ano_painel) gvar(grupo) notyet
estat simple
estat event , window(-5 5)
csdid2_plot
graph play  "csdid_red_blue"
graph export "Production\Figure6_nightl.pdf", replace


**Figure 7: Coefficients for years of PCC presence compared to baseline levels.
clear
use  "night_lights.dta"

label variable logmean "Log of DMSP"

xtreg logmean i.anos_trat, fe  
coefplot, vertical drop(_cons)
graph play "coefplot_anostrat"
graph export "Production\Figure7_night_coefs.pdf", replace



**Figure 8: Can PCC entry be explained by observable prevailing infrastructure conditions?


clear
use "census_data.dta"
set scheme s1color
label variable grupo " "


foreach x of varlist pc_2sm_2000 pc_10sm_2000 pc_2sm_2000 pc_ag_2000 pc_es_2000 pc_lix_2000 pc_anl_2000 {
quietly eststo `x' : regress `x' i.grupo, r
} 


coefplot pc_2sm_2000 , drop(_cons) xline(0) bylabel(Very low earners - %) || pc_anl_2000 , drop(_cons) xline(0) bylabel(Iliteracy - %) ||   pc_10sm_2000, drop(_cons) xline(0) bylabel(High earners - %) || pc_ag_2000, drop(_cons) xline(0) bylabel(Access to Water - %) || pc_es_2000, drop(_cons) xline(0) bylabel(Access to Sewage - %)||  pc_lix_2000, drop(_cons) xline(0) bylabel(Garbage Management - %)   ytitle("Year of PCC entry")
graph export "Production\Figure8_census1.pdf",  as(pdf) replace

 

**Figure 9: Can PCC entry be explained by observable prevailing social conditions?
clear
use "census_data.dta"
set scheme s1color
label variable grupo " "

foreach x of varlist pc_ag_2000 pc_es_2000 pc_lix_2000 ban_p_2000 ren_sm_2000 pc_10sm_2000 {
egen max_`x' = max(`x')
egen min_`x' = min(`x')    
gen int_`x' = (max_`x' - `x')/(max_`x' - min_`x')
gen `x'_normal = 1 - int_`x' 
 }

foreach x of varlist pc_2sm_2000 pc_anl_2000 densidade2000 {
egen max_`x' = max(`x')
egen min_`x' = min(`x')    
gen int_`x' = (min_`x' - `x')/(min_`x' - max_`x')
gen `x'_normal = 1 - int_`x' 
}
  
gen ids = (pc_ag_2000_normal + pc_es_2000_normal +  pc_lix_2000_normal +  ban_p_2000_normal + ren_sm_2000_normal  + pc_10sm_2000_normal + pc_2sm_2000_normal + pc_anl_2000_normal) / 8  
  
foreach x of varlist ids ren_sm_2000_normal ban_p_2000_normal densidade2000_normal densidade2000 {
quietly eststo `x' : regress `x' i.grupo, r
} 

coefplot ids , drop(_cons) xline(0) bylabel(Socioeconomic Development Index) || ren_sm_2000_normal, drop(_cons) xline(0) bylabel(Income level (normalized)) ||  densidade2000, drop(_cons) xline(0) bylabel(Population density)  ||  ban_p_2000_normal, drop(_cons) xline(0) bylabel(Access to bathroom Index)  ytitle("Year of PCC entry")
graph export "Production\Figure9_census2.pdf",  as(pdf) replace



